<script>
$(function(){
	
	$("#submitDiv").dialog({
		autoOpen:false,
		width:400,
		height:335,
		modal:true,
		show:"slide",
		buttons: {
			'OK': function() {
				modifyPwd();
			},
	    	'Cancel': function() {
				$(this).dialog('close');
			 }
		}
	});
	
	$("#operate-tip").dialog({
		autoOpen:false,
		modal:true,
		width:300,
		show:"slide",
		buttons:{
			"Close":function(){
				$(this).dialog("close");
			}
		}
	});
		$("#tipDialog").dialog({
			autoOpen:false,
			modal:true,
			show:"slide",
			buttons:{
				"OK":function(){
					location.reload();
				}
			}
		});
		$(".submit1").click(function(){
			var options = {
				dataType:"json",
				success:function(json){
					if(json.ask){
						$("#tipDialog").html("Update successful");
						$("#tipDialog").dialog("open");
					}else{
						$('.errorSpan').remove();
						$.each(json.error,function(k,v){
							$("."+k).after("<span style='color:red' class='errorSpan'>"+v+"</span>");
						});
						$.each(json.other,function(k,v){
							$(".other_"+k).after("<span style='color:red' class='errorSpan'>"+v+"</span>");
						})
					}
				}
			}
			$("#infoForm").ajaxSubmit(options);
		});
		$(".edit-img:eq(0),.edit-img:eq(1),.edit-img:eq(3)").bind("click",function(){
			var select = $(this).attr("field");
			$("."+select).html('<input type="text" class="onModify" field="'+select+'" value="'+$("."+select).html()+'" onblur="blurModify(this)">');
			var temp = $(".onModify").val();
			$(".onModify").val("")
			$(".onModify").focus();
			$(".onModify").val(temp);
		});
		$(".edit-img:eq(2)").bind("click",function(){
			var html = "<select onblur='selectBlur(this)' class='onModifySelect' field='"+$(this).attr("field")+"'>";
				<{foreach from=$countrys item=country}>
					html += "<option value='<{$country.country_id}>'><{$country.en_name}></option>";
				<{/foreach}>
			html += "</select>";
			$("."+$(this).attr("field")).html(html);
			$(".onModifySelect").focus();
			<{if isset($companyAdderss.cab_country_id)}>$(".onModifySelect").val('<{$companyAdderss.cab_country_id}>');<{/if}>
		});
		$(".addOther").click(function(){
			var html="";
			if($(this).val() == "1"){
				$.ajax({
					url:"/merchant/my-account/get-sender-address",
					dataType:"json",
					async:false,
					success:function(json){
						
						if(json != null){
							html = '<ul class="userinfo"><li><label><span class="user-name-2">Company Name:</span><input type="text" class="userinfo-input other_cab_company" name="otherCompanyName" value="'+json.cab_company+'"/></label></li><li><label><span class="user-name-2">Address:</span><input type="text" class="userinfo-input other_cab_street_address1" name="otherAddress" value="'+json.cab_street_address1+'"/></label></li><li><label><span class="user-name-2">City:</span><input type="text" class="userinfo-input other_cab_city"  name="otherCity" value="'+json.cab_city+'"/></label></li><li><label><span class="user-name-2">State/Province:</span><input type="text" class="userinfo-input other_cab_state" name="otherState" value="'+json.cab_state+'"/></label></li><li><label><span class="user-name-2">Zip/Postal Code:</span><input type="text" class="userinfo-input other_cab_postcode"  name="otherPostalCode" value="'+json.cab_postcode+'"/></label></li></ul>';
						}else{
							html = '<ul class="userinfo"><li><label><span class="user-name-2">Company Name:</span><input type="text" class="userinfo-input other_cab_company" name="otherCompanyName"/></label></li><li><label><span class="user-name-2">Address:</span><input type="text" class="userinfo-input other_cab_street_address1" name="otherAddress" /></label></li><li><label><span class="user-name-2">City:</span><input type="text" class="userinfo-input other_cab_city"  name="otherCity"/></label></li><li><label><span class="user-name-2">State/Province:</span><input type="text" class="userinfo-input other_cab_state" name="otherState"/></label></li><li><label><span class="user-name-2">Zip/Postal Code:</span><input type="text" class="userinfo-input other_cab_postcode"  name="otherPostalCode"/></label></li></ul>';
						}
						$("#otherAddress").html(html);
					}
				});
			}else{
				$("#otherAddress").html(html);
			}
			
		});
		<{if isset($sender)}>$(".addOther:eq(0)").click();<{/if}>
	});
	
	function blurModify(obj){
		$(obj).parent().html($(obj).val());
		$("[name="+$(obj).attr("field")+"]").val($(obj).val());
	}

	function selectBlur(obj){
		var text =$(obj).find("option:selected").text();
		$("[name="+$(obj).attr("field")+"]").val($(obj).val());
		$(obj).parent().html(text);
	}
	
//显示密码修改框
function showSubmitbox(){
	$("#returned-msg").empty();
	$("#submitDiv").dialog("open");
}

function modifyPwd(){
	$("#returned-msg").empty();
	var oldPassword = $('[name=oldPassword]').val();
	var password = $('[name=password]').val();
	var rePassword = $('[name=rePassword]').val();
	
	$.ajax({
		type:'POST',
		async:false,
		url:'/merchant/my-account/modify-password',
		dataType:'json',
		data:{'oldPassword':oldPassword,
			  'password':password,
			  'rePassword':rePassword
		},
		success:function(json){
			if(json.ask==1){
				$("#submitDiv").dialog("close");
				$("#operate-tip").html('The password is modified !');							
				$("#operate-tip").dialog("open");
				clear();
			}else {
				var html = "";
				$.each(json.error,function(k,v){
					html += v+"<br/>";
				});
				$("#returned-msg").html(html);
				
			}
		}
	});
	return false;
}

function clear(){
	
}
</script>
<script>
		var customerId = "<{$customer['customer_id']}>";
</script>
<script type="text/javascript" SRC="/js/swfobject.js"></script>
<script type="text/javascript" SRC="/js/jquery.uploadify.min.js"></script>
<script type="text/javascript" src="/js/xheditor/xheditor-1.1.13-zh-cn.min.js"></script>


<script>
	$(function() {	
		$("#uploadify").uploadify({
				'uploader' : '/js/uploadify.swf',
				'script' : "/merchant/my-account/upload-logo/customerId/"
						+ customerId,
				'cancelImg' : '/images/cancel.png',
				'queueID' : 'fileQueue',
				'auto' : true,
				'multi' : true,

				'sizeLimit' : 4294967296,
				'buttonText' : "browser",
				'queueSizeLimit' : 10,
				'simUploadLimit' : 1,
				'fileDataName' : "picture",
				'fileExt' : '.png;*.jpg;*.gif',
				'fileDesc' : "*.png *.jpg *.gif",				
				'scriptData' : {'sid' : 'dss'},
				"onComplete" : function(event, queueId, fileObj, response, data) {
					var json = "("+response+")";
					//alert(json);return;
					json = eval(json);
					if(json.ask==1){
						$("#account_logo").attr("src",json.filepath+"?t="+new Date().getTime());
						$("#company_logo").val(json.fileName);
					}else{
						$("#operate-tip").html(json.error).dialog("open");
					}
					
					
				},
				"onAllComplete" : function() {

				},
				"onError" : function(event,queueId,fileObj,errorObj) {
					alert(errorObj.type+" : "+errorObj.info);
				},
				'onSelect': function(e, queueId, fileObj)
				{
				/*alert("唯一标识:" + queueId + "\r\n" +
				"文件名：" + fileObj.name + "\r\n" +
				"文件大小：" + fileObj.size + "\r\n" +
				"创建时间：" + fileObj.creationDate + "\r\n" +
				"最后修改时间：" + fileObj.modificationDate + "\r\n" +
				"文件类型：" + fileObj.type
				);*/
				}
			});
})
</script>

<link rel="stylesheet" href="/css/uploadify.css" type="text/css" />
<div class="position"><a href='/default/index'>Home</a> &gt; <a href='/merchant/my-account'>Merchant Center</a>  &gt; Your Account &gt; Account Info</div>
<h4>Acconut Infomation</h4>
                <form action="/merchant/my-account/modify-account-info" method="post" id="infoForm">
                <ul class="userinfo">
                <li><span class="user-name">User ID:</span><span class="bold"><{$customer.customer_id}></span></li>
                <li><span class="user-name">Email:</span><span class="bold"><{$customer.customer_email}></span></li>
                <li><span class="user-name">First Name:</span><span class="bold firstName"><{$customer.customer_firstname}></span><input type='hidden' value='<{$customer.customer_firstname}>' name="firstName"/><img src="/images/edit.png" title="Click modify" class="edit-img customer_firstname" field="firstName"/></li>
                <li><span class="user-name">Last Name:</span><span class="bold lastName"><{$customer.customer_lastname}></span><input type='hidden' value='<{$customer.customer_lastname}>' name="lastName"/><img src="/images/edit.png" title="Click modify" class="edit-img customer_lastname" field="lastName"/></li>
                <li><span class="user-name">Country:</span><span class="bold country"><{if isset($currentCountry.en_name)}><{$currentCountry.en_name}><{/if}></span><input type='hidden' value='<{if isset($companyAdderss.cab_country_id)}><{$companyAdderss.cab_country_id}><{/if}>' name="country"/><img src="/images/edit.png" title="Click modify" class="edit-img cab_country_id" field="country"/></li>
                <li><span class="user-name">Phone:</span>
                	<span class="bold phone"><{$customer.customer_telephone}></span>
                	<input type='hidden' value='<{$customer.customer_telephone}>' name="phone"/>
                	<img src="/images/edit.png" title="Click modify" class="edit-img customer_telephone" field="phone"/>
                </li>
                <li>
                	<div onclick="showSubmitbox()" style="cursor:pointer;color:red;text-decoration:underline;">Change Password?</div><!--  密码修改 -->
                </li>
                </ul>
                
                <ul class="userinfo">
                <li><label><span class="user-name-2">Company Name:</span><input type="text" class="userinfo-input cab_company" name="companyName" value="<{if isset($companyAdderss['cab_company'])}><{$companyAdderss['cab_company']}><{/if}>"/></label></li>
                <li><label><span class="user-name-2">Address:</span><input type="text" class="userinfo-input cab_street_address1" name="address" value="<{if isset($companyAdderss['cab_street_address1'])}><{$companyAdderss['cab_street_address1']}><{/if}>"/></label></li>
                <li><label><span class="user-name-2">City:</span><input type="text" class="userinfo-input cab_city" name="city" value="<{if isset($companyAdderss['cab_city'])}><{$companyAdderss['cab_city']}><{/if}>"/></label></li>
                <li><label><span class="user-name-2">State/Province:</span><input type="text" class="userinfo-input cab_state"  name="state" value="<{if isset($companyAdderss['cab_state'])}><{$companyAdderss['cab_state']}><{/if}>"/></label></li>
                <li><label><span class="user-name-2">Zip/Postal Code:</span><input type="text" class="userinfo-input cab_postcode"  name="postalCode" value="<{if isset($companyAdderss['cab_postcode'])}><{$companyAdderss['cab_postcode']}><{/if}>"/></label></li>
                
                
                <li><div class="user-name-2" style="float:left;">logo:</div>
                	<input type="hidden" class="userinfo-input cab_logo"  name="company_logo" id="company_logo" value="<{$customer.customer_logo}>"/>
	                <div id="uploadFileDialog"  title="images upload" style='float:left;'>
						<div id="fileQueue"></div>
						<input type="file" id="uploadify" class="half" value="" name="uploadify"/>
					</div>
					<div style="clear:both;line-height:1px;height:1px;font-size:0px;"></div>
                </li>
                <li><span class="user-name-2">&nbsp;</span><img src="/merchant/my-account/view-logo/fileName/<{$customer.customer_logo}>" height="75" id="account_logo"></li>
                <li><label><span class="user-name-2">company introduce:</span>
                    <textarea id="elm5" name="cab_intro" class="xheditor {tools:'Bold,Italic,Underline,Strikethrough,FontColor,List,Fullscreen',skin:'default'}" rows="5" cols="50" style="width:400px;">
					<{$customer.customer_intro}>
					</textarea>
                </label>
                </li>
                </ul>
         
                <h4>How should we handle the returns?</h4>
                <div class="userinfo">
                <p><label><input type="radio" name="returnMethod" value="0" <{if $customer.return_package_proccess == 0}>checked<{/if}>/>&nbsp;&nbsp;Dispose product immediately</label> &nbsp;&nbsp;&nbsp;&nbsp; <label><input type="radio" name="returnMethod" value="1" <{if $customer.return_package_proccess == 1}>checked<{/if}>/>&nbsp;&nbsp;Inspect product visually.</label></p>
                </div>
				 <h4>Do you want to use your own shipping address on the envelope?</h4>
                <div class="userinfo">
                <p><label><input type="radio" name="hasOtherAddress" value="1" class="addOther ok" <{if isset($sender)}>checked<{/if}>/>&nbsp;&nbsp;Yes</label> &nbsp;&nbsp;&nbsp;&nbsp; <label><input type="radio" value="0" class="addOther" name="hasOtherAddress" <{if !isset($sender)}>checked<{/if}>/>&nbsp;&nbsp;No.</label></p>
                </div>
				<div id="otherAddress">
				
				</div>
                <img src="/images/submit.gif" class="submit1"/>
				</form>
<div title="Tip" style="display:none" id="tipDialog"> </div>

<style type="text/css">
div#add{
	text-align:center;
}
div.info{
	text-align:left;
}
div.item{
	margin-bottom: 12px;
}
input.text {
    height: 22px;    
    margin-left: 8px;
    border:1px solid #85C0FF;
}
span.text{
	margin-left: 8px;
}
</style>

<div id="submitDiv" title="Change your password" style="display:none;">
	<div class="info">
		<div>
			Change your password.
		</div><br />
		
		<form id="getForm" name="getForm" >		
		<div class="item">
			<span>Old password:</span>
			<span style="padding-left:23px;">
				<input type="password" name="oldPassword" id="oldPassword" class="text ui-widget-content ui-corner-all"  />
			</span>
			<div style="clear:both;"></div>
		</div>
		
		<div class="item">
			<span>New password:</span>
			<span style="padding-left:18px;">				
				<input type="password" name="password" id="password" class="text ui-widget-content ui-corner-all"  />
			</span>
			<div style="clear:both;"></div>
		</div>
		
		<div class="item">
			<span>Confirm password:</span>
			<span>				
				<input type="password" name="rePassword" id="rePassword" class="text ui-widget-content ui-corner-all"  />
			</span>
			<div style="clear:both;"></div>
		</div>
			
		</form>
		<div id="returned-msg" style="color:red;"></div>
	
	</div>
</div>

<div id="operate-tip" style="display:none"></div>